package com.ktgj.pay.controller;

import com.alipay.api.domain.FaceExtInfo;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.pay.domain.UnionPayQRCodeRequest;
import com.ktgj.pay.domain.UnionPayQRCodeResponse;
import com.ktgj.pay.payUtil.UnionPayQRCodeUtil;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@ControllerAdvice
@RestController
@RequestMapping("unionQRCodePay")
public class UnionQRCodePayController
{
    /**
     * 银联二维码支付码获取
     * @param map
     * @return
     */
    @PostMapping("/getQRCode")
    public UnionPayQRCodeResponse getQRCode(@RequestBody Map<String,String> map)
    {
        String billNo = map.get("billNo");
        String totalAmount = map.get("totalAmount");
        String notifyUrl = map.get("notifyUrl");
        UnionPayQRCodeRequest unionPayQRCodeRequest = new UnionPayQRCodeRequest();
        unionPayQRCodeRequest.setBillNo(billNo);
        unionPayQRCodeRequest.setTotalAmount(totalAmount);
        unionPayQRCodeRequest.setNotifyUrl(notifyUrl);
        UnionPayQRCodeResponse result = UnionPayQRCodeUtil.unionPayQRCodePay(unionPayQRCodeRequest);
        return result;
    }

    /**
     * 银联二维码退款
     * @param map
     * @return
     */
    @PostMapping("/qrCodeRefund")
    public UnionPayQRCodeResponse qrCodeRefund(@RequestBody Map<String,String> map)
    {
        String refundAmount = map.get("refundAmount");
        String billNo = map.get("billNo");
        String notifyUrl = map.get("notifyUrl");
        UnionPayQRCodeRequest unionPayQRCodeRequest = new UnionPayQRCodeRequest();
        unionPayQRCodeRequest.setRefundAmount(refundAmount);
        unionPayQRCodeRequest.setBillNo(billNo);
        unionPayQRCodeRequest.setNotifyUrl(notifyUrl);
        UnionPayQRCodeResponse result = UnionPayQRCodeUtil.unionPayRefund(unionPayQRCodeRequest);
        return result;
    }

    /**
     * 银联二维码订单信息查询
     * @param map
     * @return
     */
    @PostMapping("queryQRCodeOrder")
    public AjaxResult queryQRCodeOrder(@RequestBody Map<String,String> map)
    {
        String billNo = map.get("billNo");
        UnionPayQRCodeRequest unionPayQRCodeRequest = new UnionPayQRCodeRequest();
        unionPayQRCodeRequest.setBillNo(billNo);
        UnionPayQRCodeResponse result = UnionPayQRCodeUtil.unionPayBillingStatusQuery(unionPayQRCodeRequest);
        return AjaxResult.success(result);
    }
}
